#include "splashscreen.h"
#include <QPainter>

SplashScreen::SplashScreen(const QPixmap& pixmap) : QSplashScreen(pixmap)
{
    // 創建內容窗口
    m_content = new QWidget(this);
    m_layout = new QVBoxLayout(m_content);

    // 創建狀態標籤
    m_statusLabel = new QLabel(this);
    m_statusLabel->setStyleSheet("QLabel { color: #333333; font-size: 12px; }");
    m_statusLabel->setWordWrap(true);

    // 創建進度條
    m_progressBar = new QProgressBar(this);
    m_progressBar->setStyleSheet(
            "QProgressBar {"
            "   border: 1px solid #CCCCCC;"
            "   border-radius: 3px;"
            "   text-align: center;"
            "   background: #FFFFFF;"
            "}"
            "QProgressBar::chunk {"
            "   background-color: #4CAF50;"
            "   border-radius: 2px;"
            "}"
    );
    m_progressBar->setFixedHeight(15);

    // 添加到佈局
    m_layout->addWidget(m_statusLabel);
    m_layout->addWidget(m_progressBar);
    m_layout->setContentsMargins(20, 10, 20, 20);

    // 設置內容窗口的位置
    m_content->setGeometry(0, pixmap.height() - 80, pixmap.width(), 70);
    showStatusMessage("正在啟動程序...");
}

SplashScreen::~SplashScreen()
{
}

void SplashScreen::setProgress(int value, int maximum)
{
    m_progressBar->setMaximum(maximum);
    m_progressBar->setValue(value);
}

void SplashScreen::showStatusMessage(const QString& message, const Qt::Alignment &alignment)
{
    m_message = message;
    m_statusLabel->setText(message);
    m_statusLabel->setAlignment(alignment);
}

void SplashScreen::drawContents(QPainter *painter)
{
    QSplashScreen::drawContents(painter);
}